<template>
  <el-dialog class="custom-loading-svg" v-model="props.detailsList" width="80%" :before-close="closedetailsList"
    :title="props.title">

    <!-- 头部内容 -->
    <div class="root">

      <div class="top">

        <div class="div">
          <span>总分</span>
          <div>{{ arr.scores }}</div>
        </div>

        <div class="div">
          <span>通过分数</span>
          <div>{{ arr.pastscores }}</div>
        </div>

        <div class="div">
          <span>考试时长</span>
          <div>
            {{ arr.limittime===0? '不限' : '' }}分钟
          </div>
        </div>

        <div class="div">
          <span>开放时间</span>
          <div>
            {{ arr.begintime }} 至 {{ arr.currenttime }}
          </div>
        </div>

      </div>

      <el-button @click="excel">导出excel</el-button>

    </div>

    <div class="borderBox" />

    <!-- 内容 -->
    <div class="content">


      <div v-for="(item , index) in arr.questions">

      <!-- 内容的头部 -->
        <div class="title">
          <div>{{index+1}}.{{item.type}}</div>
        </div>
      
      <!-- 内容 -->
        <div class="Question" v-html="item.title"></div>

      <!-- 正确答案 -->
        <div class="yess" v-if="item.type == '填空题' || item.type == '判断题'">
          正确答案：{{item.answer}}
        </div>

      <!-- 解析 -->
        <div class="yess" v-if="item.type == '填空题' || item.type == '问答题'">
          解析：{{item.explains}}
        </div>

      <!-- 单选 -->
        <div class="redi" v-if="item.type === '单选题'" v-for="items in item.answers"> <!-- answers[] 是学生选的题-->
          <div :class="item.answer === items.answerno? 'line answer ' : 'answer' "> <!--判断正确答案和单选的数据是否相等-->
            <div class="redio"></div>
            <span>{{items.answerno}} &nbsp; {{items.content}}</span>
          </div>
        </div>

      <!-- 多选 -->
        <div class="redi" v-if="item.type === '多选题'" v-for="items in item.answers"> <!-- answers[] 是学生选的题-->
          <div :class="item.answer.includes(items.answerno)? 'line checkbox ' : 'checkbox' "><!--判断正确答案和多选的数据是否相等-->
            <div class="checkbox1"></div>
            <span>{{items.answerno}} &nbsp; {{items.content}}</span>
          </div>
        </div>

      </div>

    </div>


  </el-dialog>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import * as XLSX from "xlsx";  // 导出文件
import { singleexamination } from "../../api/test"; //接口


const props = defineProps(['detailsList', 'getid', 'title']); //父向子传参
// console.log(props.getid);
const emit = defineEmits(['closedetailsList']); //子向父传参

const closedetailsList = () => {
  emit('closedetailsList', false);
};


// 接口 单个考试信息
let arr: any = ref({})

let testget = async () => {
  let res = await singleexamination({ id: props.getid })
  console.log(res);
  arr.value = res.data
}
console.log(arr);

testget()


// 导出
let excel = () => {
  // 1.创建工作表
  let data = XLSX.utils.json_to_sheet(arr.value.questions)
  // 2.创建工作簿
  let wb = XLSX.utils.book_new()
  // 3.把工作表放到工作簿中
  XLSX.utils.book_append_sheet(wb,data,"data")
  // 4.生成文件并下载
  XLSX.writeFile(wb,arr.value.title+'.xlsx')
}


</script>

<style lang="less" scoped>
.top {
  display: flex;
}

.div {
  margin-right: 25px;

  span {
    line-height: 30px;
  }
}
.borderBox{
  margin-top: 10px;
  border-bottom: 1px solid rgb(210, 207, 207);
}
.title{
  margin-top: 20px;
  margin-left: 15px;
}
.Question{
  margin-top: 10px;
  margin-left: 26px;
}
.yess {
  width: 98%;
  height: 50px;
  background-color: #eefaf6;
  color: #5acda6;
  line-height: 50px;
  margin: 10px 0;
  padding-left: 10px;
}
.redi{
  margin-left: 20px;
}
.answer {
  display: flex;
  line-height: 37px;
  .redio {
    border: 1px solid #e7f0ed;
    height: 20px;
    width: 20px;
    border-radius: 15px;
    background-color: #f5f5f5;
    margin-left: 15px;
    margin-right: 9px;
    margin-top: 6px;
  }
}
.checkbox {
  display: flex;
  line-height: 37px;
  .checkbox1 {
    border: 1px solid #e7f0ed;
    height: 20px;
    width: 20px;
    border-radius: 3px;
    background-color: #f5f5f5;
    margin-left: 15px;
    margin-right: 9px;
    margin-top: 6px;
  }
}
.line{
  width: 100%;
  background-color: #eefaf6;
}

.root{
  display: flex;
  justify-content: space-between;
}
</style>
